<template>
    <view class="bg-content">
        <scroll-view scroll-x="true">
            <div class="table table-bordered" style="background-color: white; text-align: center; width: 1000px; overflow: auto;">
                <div class="tr">
                    <div class="td text-center bold" style="width: 250px;">标题扩展内容</div>
                    <div class="td text-center bold" style="width: 150px;">标题扩展位置</div>
                    <div class="td text-center bold" style="width: 200px;">开始时间</div>
                    <div class="td text-center bold" style="width: 200px;">结束时间</div>
                    <div class="td text-center bold" style="width: 100px;">状态</div>
                    <div class="td text-center bold" style="width: 100px;">操作</div>
                </div>
                <div class="tr" v-for="(item, index) in tbGoodsTitleExtendList" :key="item.id">
                    <div class="td" style="width: 250px;">{{item.title | toEmptyStr}}</div>
                    <div class="td" style="width: 150px;">{{item.positionText | toEmptyStr}}</div>
                    <div class="td" style="width: 200px;">{{item.startTime | toEmptyStr}}</div>
                    <div class="td" style="width: 200px;">{{item.endTime | toEmptyStr}}</div>
                    <div class="td" style="width: 100px;">{{item.statusText | toEmptyStr}}</div>
                    <div class="td" style="width: 100px;">
                        <div style="margin-top: 5px; text-decoration: underline;"
                             @click="navigateTo('/pages/sub/sub2-store-platform/store-platform/store-platform-goods-manage/store-platform-goods-title-extend/store-platform-goods-title-extend-edit/index', null, item)">
                            编辑
                        </div>
                        <div style="margin-top: 10px; margin-bottom: 10px; text-decoration: underline;" @click="deleteItem(item, index)">
                            删除
                        </div>
                    </div>
                </div>
            </div>
        </scroll-view>

        <div style="padding-top: 50px;" v-if="!tbGoodsTitleExtendList.length">
            <u-empty text="数据为空" mode="data"></u-empty>
        </div>

        <div style="margin-top: 10px;">
            <storePlatformGoodsTitleExtendGoods ref="storePlatformGoodsTitleExtendGoodsRef" v-if="isRefreshed"></storePlatformGoodsTitleExtendGoods>
        </div>

        <div style="padding-bottom: 60px;"></div>

        <div class="custom-bottom-button">
            <label @click="navigateTo('/pages/sub/sub2-store-platform/store-platform/store-platform-goods-manage/store-platform-goods-title-extend/store-platform-goods-title-extend-add/index')">
                添加商品标题扩展
            </label>
        </div>
    </view>
</template>

<script>

    import {CommonUtil} from "@/dev/core/utils/common.util";
    import {TbGoodsTitleExtendService} from "@/dev/services/tb-goods-title-extend.service";
    import storePlatformGoodsTitleExtendGoods from './store-platform-goods-title-extend-goods/index'

    export default {
        data() {
            return {
                tbGoodsTitleExtendList: [],
                isRefreshed: true
            }
        },
        components: {
            storePlatformGoodsTitleExtendGoods
        },
        onShow() {
            const _self = this;
            _self.findTbGoodsTitleExtendList();
            _self.isRefreshed = false;
            _self.$nextTick(() => {
                _self.isRefreshed = true;
            });
        },
        // 上拉加载
        onReachBottom: function () {
            if (this.$refs.storePlatformGoodsTitleExtendGoodsRef.pagination.hasNextPage) {
                this.$refs.storePlatformGoodsTitleExtendGoodsRef.doInfinite();
            }
        },
        methods: {
            findTbGoodsTitleExtendList() {
                const _self = this;
                new TbGoodsTitleExtendService().findTbGoodsTitleExtendList({
                    storeId: _self.globalVariable.userInfo.tbStore.id
                }).then(result => {
                    _self.tbGoodsTitleExtendList = result;
                });
            },
            /**
             * @param item
             * @param index
             */
            deleteItem(item, index) {
                const _self = this;
                CommonUtil.alert({
                    title: '提示！',
                    content: '确定删除吗？',
                    showCancel: true, // 是否显示取消按钮
                    success: function (res) {
                        if (res.cancel) { // 点击取消,默认隐藏弹框
                        } else { // 点击确定
                            new TbGoodsTitleExtendService().batchDeleteTbGoodsTitleExtendByIds(item.id).then(result => {
                                CommonUtil.toast("删除成功");
                                _self.tbGoodsTitleExtendList.splice(index, 1);
                            });
                        }
                    }
                });
            }
        }
    }
</script>

<style lang="scss" scoped>
</style>
